package com.AAA.service.Impl;

import com.AAA.entity.TRoleMenu;
import com.AAA.service.TRoleMenuService;
import com.AAA.dao.TRoleMenuMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * (TRoleMenu)表服务实现类
 *
 * @author makejava
 * @since 2022-10-26 14:41:35
 */
@Service
public class TRoleMenuServiceImpl implements TRoleMenuService {
   @Autowired
   private TRoleMenuMapper tRoleMenuMapper;

   @Override
   public boolean updRoleMenu(Integer rid, String mids) {
      //mids  1,2,3,4,5
      int insert=-1;
      System.out.println(rid+"rid");
      System.out.println("mids = " + mids);
      //删除当前角色的id拥有的菜单
      TRoleMenu tRoleMenu = new TRoleMenu();
      tRoleMenu.setRid(rid);
      int delete = tRoleMenuMapper.delete(tRoleMenu);

      //给当前角色添加新的菜单的信息
      if (mids!=null){
         String[] misstr=mids.split(",");
         for (String mid : misstr){
            int i = Integer.parseInt(mid);
            TRoleMenu tRoleMenu1 = new TRoleMenu(rid, i);
            insert = tRoleMenuMapper.insert(tRoleMenu1);

         }

      }


      return insert>0?true:false;

   }
}
